//
//  ViewController.m
//  ControlFun
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sliderChanged:(UISlider *)sender {
    int value = sender.value;
    self.sliderValueLabel.text = [NSString stringWithFormat:@"%i",value];
}

- (IBAction)segementChanged:(UISegmentedControl *)sender {
    if(sender.selectedSegmentIndex == 0)
    {
        self.leftSwitch.hidden = NO;
        self.rightSwitch.hidden = NO;
        self.doSomethingBtn.hidden = YES;
    }
    else
    {
        self.leftSwitch.hidden = YES;
        self.rightSwitch.hidden = YES;
        self.doSomethingBtn.hidden = NO;
    }

}

- (IBAction)switchChanged:(UISwitch *)sender {
    BOOL open = sender.on;
    
    [self.leftSwitch setOn:open animated:YES];
    [self.rightSwitch setOn:open animated:NO];
}

- (IBAction)doSomethingBtnPressed:(UIButton *)sender {
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"你确定吗？" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"是的，我确定" otherButtonTitles: nil];
    [sheet showInView:self.view];
}

#pragma mark - UIActionSheetDelegate Method 操作表的代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"某些事项被执行了"  // 标题
                                                            message:[NSString stringWithFormat:@"%@,放轻松，一切都正常运行了！",_nameTextField.text] // 信息
                                                           delegate:self         // 代理人(即哪个对象来处理这个UIAlertView对象的事件)
                                                  cancelButtonTitle:@"欧，耶！"       // 按钮上的文字
                                                  otherButtonTitles:nil];        // 更多按钮
        [alertView show];
    }
}

- (IBAction)backTap:(id)sender {
    [self.view endEditing:YES];
}



@end
